package com.lhj.springboot.actuator.health;

import com.lhj.springboot.actuator.component.MyHealthComponent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.stereotype.Component;

/**
 * @Description 要实现对某个主键的健康检测 方法一：实现HealthIndicator接口 方法二：继承
 * @Author lhj
 * @Date 2024/7/23 20:49
 */
@Component
public class MyHealthIndicator implements HealthIndicator {
    
    @Autowired
    MyHealthComponent healthComponent;
    
    @Override
    public Health health() {
        int check = healthComponent.check();
        if (check == 1) {
            return Health.up()
                    .withDetail("status", "success")
                    .withDetail("msg", "应用正常")
                    .build();
        }
        return Health.down()
                .withDetail("status", "error")
                .withDetail("msg", "应用异常")
                .build();
    }
}


/*
public class MyHealthIndicator1 extends AbstractHealthIndicator {


    @Override
    protected void doHealthCheck(Health.Builder builder) throws Exception {
        
    }
}*/
